#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#define ll long long
using namespace std;
struct node{
	int f;
	int a,b,c,d,e;
	char s1,s2,s3,s4;
}x[1010];
int n;
string s;
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		if(s[0]=='S') x[i].f=1;
		else x[i].f=2;
		scanf("%d%c%d%c%d%c%d%c%d",&x[i].a,&x[i].s1,&x[i].b,&x[i].s2,&x[i].c,&x[i].s3,&x[i].d,&x[i].s4,&x[i].e);
		if(x[i].a<0||x[i].a>255||x[i].b<0||x[i].b>255||x[i].c<0||x[i].c>255||x[i].d<0||x[i].d>255||x[i].e<0||x[i].e>65535||x[i].s1!='.'||x[i].s2!='.'||x[i].s3!='.'||x[i].s4!=':')
			printf("ERR\n");
		
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
 } 
